﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.SysConfig.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysConfig;
/// <summary>
/// 通过配置编号更新系统配置服务
/// </summary>
public class UpdateSysConfigByConfigIdService : ApiBase<RequestUpdateSysConfigByConfigIdModel>
{
    /// <summary>
    /// 系统配置仓储
    /// </summary>
    public SysConfigRep sysConfigRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new SysConfigModel();

        model.ConfigId = Parameter.ConfigId;
        model.ConfigName = Parameter.ConfigName;
        model.ConfigKey = Parameter.ConfigKey;
        model.ConfigValue = Parameter.ConfigValue;
        model.ConfigType = Parameter.ConfigType;
        model.Remark = Parameter.Remark;
        model.UpdateBy = userKey?.ToString();

        var res = sysConfigRep.UpdateSysConfigByConfigId(model);

        if (res > 0)
        {
            Result.Data = sysConfigRep.GetSysConfigByConfigId(Parameter.ConfigId);
        }
        else
        {
            Result.Data = res;
        }
    }
}

